package com.idrl.dao.po;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * 月历对象。
 * 默认为当前月
 * @author Administrator
 *
 */
public class MonthInfo 
{	
	private Date currDate;

	private int firstIndex;  //1号位置
	private int lastIndex;  //31号位置

	private List<DayInfo> dayList;
    
	private void init()
	{		
		dayList = new ArrayList<DayInfo>();
		Calendar cal = Calendar.getInstance();		
		cal.setTime(currDate);
		cal.roll(Calendar.DAY_OF_MONTH, false);
		cal.setFirstDayOfWeek(Calendar.SUNDAY);
		firstIndex = cal.get(Calendar.DAY_OF_WEEK) - 1;  //1号位置
		lastIndex = firstIndex + cal.getActualMaximum(Calendar.DAY_OF_MONTH); //最后一天的位置		
		int maxIndex = cal.getActualMaximum(Calendar.WEEK_OF_MONTH) * 7;
	    for(int i = 0; i < firstIndex; i++) 
	    { 
	    	dayList.add(new DayInfo("")); 
	    }
	    
	    for(int i = firstIndex; i < lastIndex; i++) 
	    { 
	    	dayList.add(new DayInfo(String.valueOf(i + 1 - firstIndex))); 
	    }
	    
	    
	    for(int i = lastIndex; i < maxIndex; i++) 
	    { 
	    	dayList.add(new DayInfo("")); 
	    }
	}

	/**
	 * 默认为当前月。
	 *
	 */
	public MonthInfo() {
		this.currDate = new Date();
		init();
	}
	
	public MonthInfo(Date currDate) {
		this.currDate = currDate;
		init();
	}



	public Date getCurrDate() {
		return currDate;
	}

	public void setCurrDate(Date currDate) {
		this.currDate = currDate;
		init();
	}

	public List<DayInfo> getDayList() {
		return dayList;
	}

	public void setDayList(List<DayInfo> dayList) {
		this.dayList = dayList;
	}
	
	public int getFirstIndex() {
		return firstIndex;
	}

	public int getLastIndex() {
		return lastIndex;
	}
	
	/**
     * 调用ToStringBuilder进行反射属性。
     */
    public String toString()
    { 
        return ToStringBuilder.reflectionToString(this);        
    }
}
